﻿package cn.poco.pepsi.util.xmlparse;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.ClassBean;

public class ClassXmlparse {
	//private final static String TAG = "DisAreaXmlparse";
	private static ArrayList<ClassBean> ClassBeans = null;
	private static  ClassBean classBean = null;
	
	public static ArrayList<ClassBean> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				ClassBeans = new ArrayList<ClassBean>();
				break;
			case XmlPullParser.START_TAG:
				if("class".equals(xmpparse.getName())){
					classBean = new ClassBean();
				}
				if(classBean!=null){
					if("id".equals(xmpparse.getName())){
						String id = xmpparse.nextText();
						classBean.setId(id);
					}
					if("name".equals(xmpparse.getName())){
						String name = xmpparse.nextText();
						classBean.setName(name);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("class".equals(xmpparse.getName())){
					ClassBeans.add(classBean);
					classBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return ClassBeans;
	}
}
